package day2;
import java.util.ArrayList;
import java.util.LinkedList;

import javax.swing.plaf.synth.SynthGraphicsUtils;

import org.junit.Test;

public class Day2 {

	@Test
	public void test1() {
		int type = 3;
		switch (type) {
		case 1:
			System.out.println("1");
			break;
		case 2:
			System.out.println("2");
			break;
		case 3:
			System.out.println("3");
			break;
		case 4:
			System.out.println("4");
			break;
		default:
			System.out.println("default");
			break;
		}
	}
	
//  >=90   <=100   优秀
//  >=80    <90       良好
//  >=70    <80       一般
//  >=60    <70      及格
//  <60     不及格
	@Test
	public void test2() {
		int score = 18;
		if (score >= 90 && score <= 100) {
			System.out.println("优秀");
		} else if (score >= 80 && score < 90) {
			System.out.println("良好");
		} else if (score >= 70 && score < 80) {
			System.out.println("一般");
		} else if (score >= 60 && score < 70) {
			System.out.println("及格");
		} else {
			System.out.println("不及格");
		}
	}
	
	@Test
	public void test3() {
		int score = 98;
		// int type = score / 10;
		switch (score / 10) {
		case 10:
		case 9:
			System.out.println("优秀");
			break;
		case 8:
			System.out.println("良好");
			break;
		case 5:
		case 4:
		case 3:
		case 2:
		case 1:
		case 0:
			System.out.println("不及格");
			break;
		default:
			System.out.println("default");
			break;
		}
	}
	
	// continue、break
	@Test
	public void test23() {
		for (int i = 1; i <= 10; i++) {
			if (i == 3) {
				break;
			}
			System.out.println(i);
		}
		System.out.println("----------------");
		
		for (int i = 1; i <= 10; i++) {
			if (i == 3) {
			    continue;
			}
			
			System.out.println(i);
		}
	}
	
	
	@Test
	public void test333() {
		for (int i = 1; i <= 5; i++) {
			for (int j = 1; j <= 5; j++) {
				if (j == 3) {
					break;// 只能退出离他最近的那一层循环
				}
				System.out.println(j);
			}
		}
		for (;;) {
			
		}
	}
	
	@Test
	public void test44() {
		Student student = new Student();
		// student.age = 333;
		student.setId(1);
		student.setName("张三");
		student.setAge(23);
		student.setGender("男");
		
		// name
		int id = student.getId();
		String name = student.getName();
		int age = student.getAge();
		String gender = student.getGender();
		System.out.println("id: " + id + ", name: " + name + ", age: " + age + ", gender: " + gender);
		System.out.println(student);// 直接打印student对象，默认调用的就是student.toString();
		System.out.println(student.toString());
		
		Student student1 = new Student(1, "李四", 23, "男");
		System.out.println(student1.getName());
		System.out.println(student1);
	}
	
	@Test
	public void test33() {
		Student student1 = new Student(1, "张三", 23, "男");
		Student student2 = new Student(2, "李四", 23, "男");
		Student student3 = new Student(3, "王五", 23, "男");
		Student student4 = new Student(4, "赵六", 23, "男");
		int[] array1 = new int[4];
		String[] array2 = new String[4];
		Student[] array = new Student[4];
		array[0] = student1;
		array[1] = student2;
		array[2] = student3;
		array[3] = student4;
		for (int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
		}
		System.out.println("----------------");
		// 数组的操作有一个非常大的缺点：长度固定，而且数组通过下标操作比较麻烦
		// ArrayList:就是对数组的封装，我们不再需要考虑数组的长度问题，也不需要通过下标操作
		// LinkedList<Student>
		ArrayList<Student> list = new ArrayList<Student>();
		list.add(student1);
		list.add(student2);
		list.add(student3);
		list.add(student4);
		// foreach
		for (Student student : list) {
			System.out.println(student);
		}
	}
	
	
	
}
